package duck.factory;

import humans.Quackologist;
import duck.ObservedQuack;
import duck.QuackCounterable;
import duck.Quackable;

public class ObservableCounterableDuckFactory extends DuckFactory {
	
	Quackologist observer;
	
	public ObservableCounterableDuckFactory() {
		super();
		observer = Quackologist.getInstance();
	}
	
	//TODO <?>
	//TODO try - catch
	@Override
	protected Quackable getDuck(Class<?> duckClass) { //throws InstantiationException, IllegalAccessException {
		try {
			
			ObservedQuack q = new ObservedQuack ((Quackable) duckClass.newInstance());
			q.addObserver(observer);
			return new QuackCounterable( q );
		} catch (Exception e) {
			System.out.println("DuckFactory > getDuck > somthing was wrong with instantiating classes..");
			System.out.println(e);
			e.printStackTrace();
			return null;
		}
	}
}
